package com.ktjy.ch15.service.impl;

import com.ktjy.ch15.entity.Computerroom;
import com.ktjy.ch15.mapper.ComputerroomMapper;
import com.ktjy.ch15.service.ComputerroomService;
import com.ktjy.ch15.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("computerroomService")
public class ComputerroomServiceImpl implements ComputerroomService {

    @Autowired
    ComputerroomMapper computerroomMapper;

    @Override
    public Page<Computerroom> findPage(Computerroom computerroom, Integer pageNo, Integer pageSize) {
        Page<Computerroom> page = new Page<Computerroom>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        // 查询总数，计算总页数
        Integer count = computerroomMapper.count(computerroom);
        page.setTotalCount(count);
        // 查询分页数据
        Integer pageBegin=(pageNo-1)*pageSize;
        List<Computerroom> data = computerroomMapper.getPage(computerroom, pageBegin, pageSize);
        page.setData(data);
        return page;
    }

    @Override
    public boolean save(Computerroom computerroom) {
        return computerroomMapper.insert(computerroom) > 0;
    }

    @Override
    public Computerroom findByRoomId(Long roomId) {
        return computerroomMapper.getByRoomId(roomId);
    }

    @Override
    public boolean update(Computerroom computerroom) {
        return computerroomMapper.update(computerroom) > 0;
    }

    @Override
    public boolean delete(Long roomId) {
        return computerroomMapper.delete(roomId) > 0;
    }

    @Override
    public Computerroom findByRoomName(String roomName) {
        return computerroomMapper.getByRoomName(roomName);
    }
}
